import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
  

Vue.use(VueRouter)



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


 import { get_token } from '@/utils/auth'

import nProgress from 'nprogress'

import { check_login } from '@/api/login'


router.beforeEach((to, from, next) => {
  document.title=to.meta.title||"在线学习平台";
  nProgress.start(); 
  if (!to.meta.not_check) {
    if (!get_token()) {
      next('login');
      return;
    }

    check_login({})
  }
  next();
});

router.afterEach(() => {
  nProgress.done();
});

export default router
